<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of UserBaseModel
 *
 * @author wutian1
 */

namespace Home\Model ;

class UserBaseModel extends \Think\Model
{

    //查询用户基本信息
    function getUserBaseInfor ()
    {
        $front                 = $this->where ( 'UDepartment="前端部"' )->select () ;
        $back                  = $this->where ( 'UDepartment="后端部"' )->select () ;
        $design                = $this->where ( 'UDepartment="设计部"' )->select () ;
        $market                = $this->where ( 'UDepartment="市场部"' )->select () ;
        $management            = $this->where ( 'UDepartment="管理层"' )->select () ;
        $array[ 'front' ]      = $front ;
        $array[ 'back' ]       = $back ;
        $array[ 'design' ]     = $design ;
        $array[ 'market' ]     = $market ;
        $array[ 'management' ] = $management ;
        return $array ;
    }

    //添加用户基本信息
    function addUserBaseInfor ( $UID , $UName , $UTelephoneNumber , $UQQ ,
            $UEmail , $UDepartment , $PicturePath )
    {

        $map[ 'UID' ]              = $UID ;
        $map[ 'UName' ]            = $UName ;
        $map[ 'UTelePhoneNumber' ] = $UTelephoneNumber ;
        $map[ 'UQQ' ]              = $UQQ ;
        $map[ 'UEmail' ]           = $UEmail ;
        $map[ 'UDepartment' ]      = $UDepartment ;
        $map[ 'PicturePath' ]      = $PicturePath ;
        if ( $this->create ( $map ) )
        {
            if ( ! $this->add () )
            {
                return false ;
            }
            return true ;
        }
        return false ;
    }

    // 修改用户基本信息
    function updateUserBaseInforByUID ( $UID , $UName , $UTelePhoneNumber ,
            $UQQ , $UEmail , $UDepartment )
    {

        $map[ 'UID' ]              = $UID ;
        $map[ 'UName' ]            = $UName ;
        $map[ 'UTelePhoneNumber' ] = $UTelePhoneNumber ;
        $map[ 'UQQ' ]              = $UQQ ;
        $map[ 'UEmail' ]           = $UEmail ;
        $map[ 'UDepartment' ]      = $UDepartment ;
        $rs                        = $this->where ( 'UID = %d' , $UID )->save ( $map ) ;
        if ( false === $rs )
        {
            return false ;
        }
        else
        {
            return true ;
        }
    }

    //删除用户
    function deleteUser ( $UID )
    {
        $rs = $this->where ( 'UID = %d' , $UID )->delete () ;
        return $rs ? true : false ;
    }

    //通过UID获取用户姓名
    function getUserNameByUID ( $UID )
    {
        $rs = $this->where ( 'UID = %d' , $UID )->field ( 'UName' )->find () ;
        return $rs ? $rs[ 'UName' ] : false ;
    }

}
